/*
     Copyright 2007 Joseph M. Ferner

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;
using System.Net;
using System.Net.Sockets;
using OpenServers.Net.Common.Listener;
using OpenServers.Net.Common.State;

namespace OpenServers.Net.Common.Socket {
    /// <summary>
    /// interface for all sockets.
    /// </summary>
    public interface ISocket {
        /// <summary>
        /// perform async send.
        /// </summary>
        void BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state);

        /// <summary>
        /// perform async receive.
        /// </summary>
        int EndReceive(IAsyncResult ar, out SocketError socketError);

        /// <summary>
        /// begin async disconnect.
        /// </summary>
        void BeginDisconnect(bool reuseSocket, AsyncCallback callback, object state);

        /// <summary>
        /// close the socket.
        /// </summary>
        void Close();

        /// <summary>
        /// begin async send.
        /// </summary>
        void BeginSend(byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state);

        /// <summary>
        /// end async send.
        /// </summary>
        int EndSend(IAsyncResult ar, out SocketError socketError);

        /// <summary>
        /// gets the local address of this socket.
        /// </summary>
        IPAddress LocalAddress { get; }

        /// <summary>
        /// gets the local port of this socket.
        /// </summary>
        int LocalPort { get; }

        /// <summary>
        /// gets the remote address of this socket.
        /// </summary>
        IPAddress RemoteAddress { get; }

        /// <summary>
        /// gets the remote port of this socket.
        /// </summary>
        int RemotePort { get; }

        /// <summary>
        /// bind this socket to a local address and port.
        /// </summary>
        void Bind(IPAddress address, int port);

        /// <summary>
        /// begin an async connection.
        /// </summary>
        void BeginConnect(IPAddress address, int port, AsyncCallback callback, object state);

        /// <summary>
        /// end async connect.
        /// </summary>
        void EndConnect(IAsyncResult ar);

        /// <summary>
        /// end async disconnect.
        /// </summary>
        void EndDisconnect(IAsyncResult ar);
    }
}
